<?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
class SmsController extends Controller {
    /**
	* 生成短信验证码并写入session	2016-11-21
	*/
	public function createsms(){
		$mobilephone = I('request.mobilephone');
		//测试账号

		if($mobilephone=="15334509852" || $mobilephone=="17783641562"){
			$this -> ajaxReturn(array('code'=>1,'result'=>true,'checkcode'=>"0000"),'JSONP');exit;
		}
    	if(!check_mobilephone($mobilephone)){
			$this -> ajaxReturn(array('ret'=>0,'msg'=>'请输入正确的手机号'));
		}
		$checkcode = createverifycode();
		$checkinfo = array(
			'mobilephone' => $mobilephone,
			'checkcode'   => $checkcode,
		);
		$phone = M('phone_code');

		$findphone = array('mobilephone'=>$mobilephone);
		$res = $phone->where($findphone)->find();
		$checkinfo['add_time'] = time();
		if($res){
			$phone->where($findphone)->save($checkinfo);
		}else{
            // var_dump($checkinfo,'啦啦啦');die;
			$phone->add($checkinfo);
		}
		$result = messagelog($mobilephone,$checkcode);
		
		$this -> ajaxReturn(array('code'=>1,'result'=>$result,'checkcode'=>$checkcode),'JSONP');
	}
}